package com.indusfo.spc.controller;

import com.indusfo.spc.pojo.MatRepair;
import com.indusfo.spc.pojo.OrderRepair;
import com.indusfo.spc.service.OrderRepairService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author liub
 * @Date 2019/11/27 9:37
 * @Version 1.0
 */

@Controller
@RequestMapping("/service/orderRepair")
public class OrderRepairController {

    @Autowired
    private OrderRepairService orderRepairService;

    /**
     * 查询
     */
    @RequestMapping(value = "/queryOrderRepair")
    @ResponseBody
    public JSONObject queryOrderRepair(OrderRepair orderRepair) {
        JSONObject json = orderRepairService.queryOrderRepair(orderRepair);
        return json;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/insertOrderRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject insertOrderRepair(OrderRepair orderRepair) {
        JSONObject json = orderRepairService.insertOrderRepair(orderRepair);
        return json;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/updateOrderRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject updateOrderRepair(OrderRepair orderRepair) {
        JSONObject json = orderRepairService.updateOrderRepair(orderRepair);
        return json;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/deleteOrderRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteOrderRepair(@RequestParam("orderRepairIds") List<Integer> orderRepairIds, Integer dataState) {
        dataState = 2;
        JSONObject json = orderRepairService.deleteOrderRepair(orderRepairIds, dataState);
        return json;
    }

    /**
     * 级联删除维修流程关联的工序、维修采集参数
     */
    @RequestMapping(value = "/deleteCascadeOrderRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteCascadeOrderRepair(@RequestParam("orderRepairIds") List<Integer> orderRepairIds, Integer dataState) {
        dataState = 2;
        try {
            return orderRepairService.deleteCascadeMatRepair(orderRepairIds, dataState);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONObject.build(JSONObject.ERROR, e.getMessage(), null);
        }
    }

    /**
     * 启停
     */
    @RequestMapping(value = "/definedOrderRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject definedOrderRepair(@RequestParam("orderRepairIds") List<Integer> orderRepairIds, Integer dataState) {
        JSONObject json = orderRepairService.deleteOrderRepair(orderRepairIds, dataState);
        return json;
    }

    /**
     * 任务单流程维修工序
     */
    @RequestMapping(value = "/saveOrderRepairFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveOrderRepairFlow(@RequestBody OrderRepair orderRepair) {
        JSONObject json = orderRepairService.saveOrderRepairFlow(orderRepair);
        return json;
    }
    /**
     * 任务单流程维修工序 复制
     */
    @RequestMapping(value = "/copyOrderRepairFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject copyOrderRepairFlow(@RequestBody OrderRepair orderRepair) {
        JSONObject json = orderRepairService.copyOrderRepairFlow(orderRepair);
        return json;
    }
    /**
     * 任务单流程维修采集参数
     */
    @RequestMapping(value = "/saveOrderRepairDete", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveOrderRepairDete(@RequestBody OrderRepair orderRepair) {
        JSONObject json = orderRepairService.saveOrderRepairDete(orderRepair);
        return json;
    }

    /**
     * 任务单流程维修采集参数 复制
     */
    @RequestMapping(value = "/copyOrderRepairDete", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject copyOrderRepairDete(@RequestBody OrderRepair orderRepair) {
        JSONObject json = orderRepairService.copyOrderRepairDete(orderRepair);
        return json;
    }
}
